<!DOCTYPE html>



  


<html class="theme-next muse use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />







<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.4" rel="stylesheet" type="text/css" />


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png?v=5.1.4">


  <link rel="mask-icon" href="/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="Hexo, NexT" />










<meta name="description" content="阶段要学习的内容 Vuejs 基础语法 Vue-router (前端路由组件) Vuex (全局状态管理器) axios (可用在前端&#x2F;Node的请求模块) Vue-cli2 (vue2.x) 脚手架模板 组件库的学习  简介(What)​    它是一个渐进式的前端框架, 底层还是封装的原生JS  ​    渐进式: 由底向上逐级开发组件, 增量开发, 构成我们的应用  为什么学?(Why)​">
<meta name="keywords" content="君须知，未见之处，犹多宝藏">
<meta property="og:type" content="article">
<meta property="og:title" content="初识Vue">
<meta property="og:url" content="http:&#x2F;&#x2F;yoursite.com&#x2F;2019&#x2F;11&#x2F;15&#x2F;%E5%88%9D%E8%AF%86Vue&#x2F;index.html">
<meta property="og:site_name" content="White 的个人博客">
<meta property="og:description" content="阶段要学习的内容 Vuejs 基础语法 Vue-router (前端路由组件) Vuex (全局状态管理器) axios (可用在前端&#x2F;Node的请求模块) Vue-cli2 (vue2.x) 脚手架模板 组件库的学习  简介(What)​    它是一个渐进式的前端框架, 底层还是封装的原生JS  ​    渐进式: 由底向上逐级开发组件, 增量开发, 构成我们的应用  为什么学?(Why)​">
<meta property="og:locale" content="zh-Hans">
<meta property="og:image" content="d:%5Czg%E6%96%87%E6%A1%A3%5C%E7%AC%AC%E5%9B%9B%E9%98%B6%E6%AE%B5_%E5%A4%87%E8%AF%BE_%E6%9D%8E%E4%B8%9C%E6%97%AD%5Cday03_vue01%5C%E7%A4%BA%E4%BE%8B%5C%E6%B8%90%E8%BF%9B%E5%BC%8F%E8%AE%B2%E8%A7%A3.png">
<meta property="og:updated_time" content="2019-11-17T08:23:26.156Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="d:%5Czg%E6%96%87%E6%A1%A3%5C%E7%AC%AC%E5%9B%9B%E9%98%B6%E6%AE%B5_%E5%A4%87%E8%AF%BE_%E6%9D%8E%E4%B8%9C%E6%97%AD%5Cday03_vue01%5C%E7%A4%BA%E4%BE%8B%5C%E6%B8%90%E8%BF%9B%E5%BC%8F%E8%AE%B2%E8%A7%A3.png">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Muse',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":true,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://yoursite.com/2019/11/15/初识Vue/"/>





  <title>初识Vue | White 的个人博客</title>
  








</head>
<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>
<a href="https://github.com/whitechiina" target="_blank" rel="noopener" class="github-corner" aria-label="View source on GitHub"><svg width="80" height="80" viewBox="0 0 250 250" style="fill:#f55555; color:#fff; position: absolute; top: 0; border: 0; right: 0;" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path></svg></a>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">White 的个人博客</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle">君须知，未见之处，犹多宝藏</p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br />
            
            关于
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2019/11/15/%E5%88%9D%E8%AF%86Vue/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="White">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/1.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="White 的个人博客">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">初识Vue</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2019-11-15T23:50:34+08:00">
                2019-11-15
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/Vue/" itemprop="url" rel="index">
                    <span itemprop="name">Vue</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          

          
            <div class="post-wordcount">
              
                
                <span class="post-meta-item-icon">
                  <i class="fa fa-file-word-o"></i>
                </span>
                
                  <span class="post-meta-item-text">字数统计&#58;</span>
                
                <span title="字数统计">
                  1.9k字
                </span>
              

              
                <span class="post-meta-divider">|</span>
              

              
                <span class="post-meta-item-icon">
                  <i class="fa fa-clock-o"></i>
                </span>
                
                  <span class="post-meta-item-text">阅读时长 &asymp;</span>
                
                <span title="阅读时长">
                  7分钟
                </span>
              
            </div>
          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <h4 id="阶段要学习的内容"><a href="#阶段要学习的内容" class="headerlink" title="阶段要学习的内容"></a>阶段要学习的内容</h4><ol>
<li>Vuejs 基础语法</li>
<li>Vue-router (前端路由组件)</li>
<li>Vuex (全局状态管理器)</li>
<li>axios (可用在前端/Node的请求模块)</li>
<li>Vue-cli2 (vue2.x) 脚手架模板</li>
<li>组件库的学习</li>
</ol>
<h4 id="简介-What"><a href="#简介-What" class="headerlink" title="简介(What)"></a>简介(What)</h4><p>​    它是一个渐进式的前端框架, 底层还是封装的原生JS </p>
<p>​    渐进式: 由底向上逐级开发组件, 增量开发, 构成我们的应用</p>
<p><img src="D:%5Czg%E6%96%87%E6%A1%A3%5C%E7%AC%AC%E5%9B%9B%E9%98%B6%E6%AE%B5_%E5%A4%87%E8%AF%BE_%E6%9D%8E%E4%B8%9C%E6%97%AD%5Cday03_vue01%5C%E7%A4%BA%E4%BE%8B%5C%E6%B8%90%E8%BF%9B%E5%BC%8F%E8%AE%B2%E8%A7%A3.png" alt="渐进式讲解"></p>
<h4 id="为什么学-Why"><a href="#为什么学-Why" class="headerlink" title="为什么学?(Why)"></a>为什么学?(Why)</h4><p>​    Vuejs的速度一目了然, 容错性很高. 成吨的提高你的开发效率, 极大减少了你操作DOM的动作, 只需要关系数据和视图即可</p>
<p>​    原生Javascript:</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">&lt;body&gt;</span><br><span class="line">    &lt;ul id=<span class="string">"myUl"</span>&gt;<span class="xml"><span class="tag">&lt;/<span class="name">ul</span>&gt;</span></span></span><br><span class="line">    &lt;script&gt;</span><br><span class="line">        <span class="keyword">let</span> arr = [<span class="string">"春天"</span>, <span class="string">"夏天"</span>, <span class="string">"秋天"</span>, <span class="string">"冬天"</span>];</span><br><span class="line">        <span class="keyword">let</span> myUl = <span class="built_in">document</span>.getElementById(<span class="string">"myUl"</span>);</span><br><span class="line">        <span class="keyword">for</span> (<span class="keyword">let</span> i = <span class="number">0</span>; i &lt; arr.length; i++)&#123;</span><br><span class="line">            <span class="keyword">let</span> theLi = <span class="built_in">document</span>.createElement(<span class="string">"li"</span>);</span><br><span class="line">            theLi.innerHTML = arr[i];</span><br><span class="line">            myUl.appendChild(theLi);</span><br><span class="line">        &#125;</span><br><span class="line">    &lt;<span class="regexp">/script&gt;</span></span><br><span class="line"><span class="regexp">&lt;/</span>body&gt;</span><br></pre></td></tr></table></figure>

<p>​    Vue实现同样效果:</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">&lt;div id=<span class="string">"app"</span>&gt;</span><br><span class="line">    &lt;ul&gt;<span class="xml"><span class="tag">&lt;<span class="name">li</span> <span class="attr">v-for</span>=<span class="string">"item in arr"</span>&gt;</span>&#123;&#123;item&#125;&#125;<span class="tag">&lt;/<span class="name">li</span>&gt;</span></span><span class="xml"><span class="tag">&lt;/<span class="name">ul</span>&gt;</span></span></span><br><span class="line">&lt;<span class="regexp">/div&gt;</span></span><br><span class="line"><span class="regexp">&lt;script&gt;</span></span><br><span class="line"><span class="regexp">    new Vue(&#123;</span></span><br><span class="line"><span class="regexp">        el: "#app",</span></span><br><span class="line"><span class="regexp">        data: &#123;arr: ["春天", "夏天", "秋天", "冬天"]&#125;</span></span><br><span class="line"><span class="regexp">    &#125;)</span></span><br><span class="line"><span class="regexp">&lt;/</span>script&gt;</span><br></pre></td></tr></table></figure>

<p>​    原生js好比锯条, jq好比是带把手的锯条, vuejs电锯</p>
<h4 id="怎么学-How"><a href="#怎么学-How" class="headerlink" title="怎么学?(How)"></a>怎么学?(How)</h4><ol>
<li><p>要有html+css+javascript的基础</p>
<ol start="2">
<li>以及Vuejs的基础语法 (不建议上来就用VueCli脚手架)</li>
<li>NodeJS+Webpack的基础</li>
<li>VueJS路由学习</li>
<li>VueCli脚手架的学习和使用 (熟悉VueCli里的各项配置)</li>
<li>Vuex+脚手架里使用路由+网络请求库+组件库的学习</li>
</ol>
</li>
</ol>
<h4 id="VueJS注意事项"><a href="#VueJS注意事项" class="headerlink" title="VueJS注意事项"></a>VueJS注意事项</h4><ol>
<li>不兼容IE8及以下IE浏览器</li>
<li>建议安装vue的devtool工具, 帮助你进行调试代码</li>
<li>必须是vuejs编写的代码, 才可以在控制台使用vue调试工具</li>
</ol>
<h4 id="安装devTool工具"><a href="#安装devTool工具" class="headerlink" title="安装devTool工具"></a>安装devTool工具</h4><ol>
<li>下载: 官网(<a href="https://cn.vuejs.org/" target="_blank" rel="noopener">https://cn.vuejs.org/</a>) -&gt; 生态系统 -&gt; devTool工具</li>
<li>我们下载的是Google Chrome浏览器的插件 -&gt; 打开谷歌浏览器 -&gt; 更多工具 -&gt; 扩展程序</li>
<li>打开开发者模式, 把下载好的插件文件夹 -&gt; 拖拽扔进去即可完成安装</li>
<li>注意: 插件的文件夹不要删除/也不要随意挪动</li>
</ol>
<h3 id="使用VueJS"><a href="#使用VueJS" class="headerlink" title="使用VueJS"></a>使用VueJS</h3><ol>
<li><p>引入vuejs的js文件</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">&lt;script src=<span class="string">"https://cdn.bootcss.com/vue/2.6.6/vue.js"</span>&gt;<span class="xml"><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span></span><br></pre></td></tr></table></figure>
</li>
<li><p>声明根节点标签, 包裹着的都是Vuejs代码, 注意不能以html/body为根标签</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">&lt;div id=&quot;app&quot;&gt;&lt;/div&gt;</span><br></pre></td></tr></table></figure>
</li>
<li><p>实例化Vue对象</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">new</span> Vue(&#123;</span><br><span class="line">	el: <span class="string">"#app"</span>, <span class="comment">// 告诉vue实例, 从id叫app的标签开始, 内部都是你vue的代码</span></span><br><span class="line">&#125;)</span><br></pre></td></tr></table></figure>

</li>
</ol>
<h4 id="声明式渲染"><a href="#声明式渲染" class="headerlink" title="声明式渲染"></a>声明式渲染</h4><p>​    它就是vuejs里最独特的使用方式, 可以在html中直接书写JS的变量/表达式</p>
<p>​    js表达式: 由变量/常量+运算符 组成</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">&lt;p&gt;&#123;&#123;表达式&#125;&#125;&lt;/p&gt;</span><br></pre></td></tr></table></figure>

<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">new</span> Vue(&#123;</span><br><span class="line">	el: <span class="string">"#app"</span>,</span><br><span class="line">	data : &#123; <span class="comment">// data里都是声明的变量</span></span><br><span class="line">    	message: <span class="string">"欢迎来到vuejs的世界"</span> <span class="comment">//无需var/let, 直接书写即可!</span></span><br><span class="line">    &#125;</span><br><span class="line">&#125;)</span><br></pre></td></tr></table></figure>

<p>​    注意, 声明式渲染中, 可以写入表达式代码(包括判断/运算/条件运算符)等</p>
<p>​    例如:</p>
<pre><code>&lt;p&gt;{{ message }}&lt;/p&gt;
&lt;p&gt;{{ 10 + 5 }}&lt;/p&gt;
&lt;p&gt;{{ grade === 10 ? '等于' : '不等于' }}&lt;/p&gt;
&lt;p&gt;{{ grade > 9 }}&lt;/p&gt;</code></pre><h4 id="指令"><a href="#指令" class="headerlink" title="指令"></a>指令</h4><p>​    v- 开头的, 叫做 指令, 作用: 给标签扩展更多的功能, 因为你的属性被vue的指令修饰了, 说明现在你用的是vue的东西, 所以可以直接使用, 无需再加双大括号修饰</p>
<h5 id="v-bind"><a href="#v-bind" class="headerlink" title="v-bind"></a>v-bind</h5><p>​        给标签自带的属性, 设置一个变量的值, </p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">&lt;p v-bind:title=<span class="string">"pTitle"</span>&gt;我是个可怜, 无助, 能吃的p标签&lt;<span class="regexp">/p&gt;</span></span><br><span class="line"><span class="regexp">&lt;img :src="imgSrc" alt="" /</span>&gt;</span><br></pre></td></tr></table></figure>

<h5 id="v-on"><a href="#v-on" class="headerlink" title="v-on"></a>v-on</h5><p>​        给标签绑定事件, 注意后面的地方直接跟方法名, 如果没有参数, 则无需写小括号</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">v-on:click=<span class="string">"btn"</span></span><br><span class="line">@click=<span class="string">"btn2"</span> <span class="comment">// 事件简化写法用@</span></span><br><span class="line"></span><br><span class="line"><span class="comment">// 方法要写在new Vue() 的methods:中</span></span><br></pre></td></tr></table></figure>

<h5 id="v-if"><a href="#v-if" class="headerlink" title="v-if"></a>v-if</h5><p>​        控制标签的出现和隐藏, 用于控制标签的 出现/隐藏 如果传true则当前标签+所有子标签都出现</p>
<p>​        如果传false, 则都不会出现, 但是如果有对应的v-else会显示v-else的标签</p>
<h5 id="v-else"><a href="#v-else" class="headerlink" title="v-else"></a>v-else</h5><p>​        v-else不能单独出现, 必须配合对应的v-if使用</p>
<h5 id="v-show"><a href="#v-show" class="headerlink" title="v-show"></a>v-show</h5><p>​        跟v-if的效果一样, 唯一的区别是:</p>
<p>​        v-if 传false 时, 不会在DOM上加载这个标签</p>
<p>​        v-show 传false 时, 会在DOM上加载这个标签(利用display:none;的方式隐藏</p>
<blockquote>
<p>所以用v-if和v-show取决于标签是否要频繁的切换, 如果需要则使用v-show, 效率高, 特别是包含子标签特别多的时候</p>
</blockquote>
<h5 id="v-for"><a href="#v-for" class="headerlink" title="v-for"></a>v-for</h5><p>​        用于根据数据, 循环生成标签, 在指令里用的是最多的</p>
<p>​        item: 临时变量, 每次循环, 获取的是数组里每一项的值</p>
<p>​        in关键字(必须)</p>
<p>​        arr 代表的vue里声明的变量(数组)</p>
<p>​        index: 临时变量, 代表下角标的使用</p>
<p>​        注意1: 每个循环的标签, 需要给一个独立(不重复的)key属性的值, 用来标识唯一性, 用于部分刷新和重载数据</p>
<p>​        注意2: v-for使用位置: 确定让哪个标签循环铺设, 就在哪个标签身上写v-for</p>
<p>​        注意3: v-for里的临时变量, 只能在当前标签/子标签内使用, 不能在兄弟标签上使用</p>
<h5 id="v-model"><a href="#v-model" class="headerlink" title="v-model"></a>v-model</h5><p>​        v-model主要应用于表单标签上, value属性的绑定, 实现页面标签的value值和Vuejs变量的双向绑定 (推荐使用v-model), 页面改变表单的值, 会同步给vuejs里的变量</p>
<blockquote>
<p>注意: 只有input和textarea以及select 等表单, 有v-model, 用v-model来给表单绑定值</p>
</blockquote>
<p>​        例如: 输入框/密码框/多选/下拉/单选/textarea</p>
<p>​        注意: 多选框的v-model必须是一个数组类型</p>
<blockquote>
<p> v-model, 实际上绑定的就是value属性</p>
</blockquote>
<h5 id="v-once"><a href="#v-once" class="headerlink" title="v-once"></a>v-once</h5><p>​        v-once修饰的标签, 只有在网页打开的第一次加载完, 以后就不会在受变量变化而影响</p>
<h4 id="事件详解"><a href="#事件详解" class="headerlink" title="事件详解"></a>事件详解</h4><p>​    在事件/属性后面.xxx 叫做修饰符, 修饰符一般都有额外的功能</p>
<ol>
<li><p>@click.stop 阻止事件冒泡</p>
<ol start="2">
<li>@click.prevent 阻止默认事件</li>
<li>@click.self 只能由标签自身触发</li>
<li>@click.once 程序运行期间只能执行一次</li>
<li>@click=”btn6(myArg)” 事件传参, 如果是字符串, 请用单引号</li>
</ol>
</li>
</ol>
<blockquote>
<p>注意: 如果传参, 再使用(), 如果不传, 可以省略()不写, 如果传实践对象, 要使用$event</p>
</blockquote>
<h3 id="双向数据绑定原理"><a href="#双向数据绑定原理" class="headerlink" title="双向数据绑定原理"></a>双向数据绑定原理</h3><ol>
<li><p>页面-&gt;数据, 借助 oninput事件</p>
<ol start="2">
<li>数据-&gt;页面, 借助Object.defineProperty() 监听一个对象的属性值的变化</li>
</ol>
</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> temp = <span class="string">""</span>; <span class="comment">// 临时存储值</span></span><br><span class="line">   <span class="function"><span class="keyword">function</span> <span class="title">change</span>(<span class="params">ev</span>)</span>&#123;</span><br><span class="line">       data.message = ev.target.value; <span class="comment">// 获取输入框里最新的值</span></span><br><span class="line">   &#125;</span><br><span class="line">   <span class="keyword">let</span> data = &#123; <span class="comment">// 准备类似data里的数据</span></span><br><span class="line">       message: <span class="string">""</span></span><br><span class="line">   &#125;;</span><br><span class="line"></span><br><span class="line">   <span class="comment">// 参数1: 监听的对象, 参数2: 监听对象里的属性名, 参数3: 固定写法</span></span><br><span class="line">   <span class="built_in">Object</span>.defineProperty(data, <span class="string">"message"</span>, &#123;</span><br><span class="line">       <span class="comment">// 当你获取data对象里的message属性值的时候, 触发get方法</span></span><br><span class="line">       <span class="comment">// 不要在get方法里直接提取data.message的值, 会造成递归调用卡死.</span></span><br><span class="line">      <span class="keyword">get</span> () &#123;</span><br><span class="line">          <span class="comment">// return到你 写data.message的地方</span></span><br><span class="line">          <span class="keyword">return</span> temp;</span><br><span class="line">      &#125;,</span><br><span class="line">       <span class="comment">// data.message =  xxx 赋值的时候, 才会触发</span></span><br><span class="line">       <span class="keyword">set</span> (val) &#123;</span><br><span class="line">           <span class="comment">// 更新页面(所有跟message变量相关的界面)</span></span><br><span class="line">           <span class="built_in">document</span>.getElementById(<span class="string">"myP"</span>).innerHTML = val;</span><br><span class="line">           <span class="built_in">document</span>.getElementById(<span class="string">"myInput"</span>).value = val;</span><br><span class="line">           <span class="comment">// 更新message的值</span></span><br><span class="line">           temp = val;</span><br><span class="line">       &#125;</span><br><span class="line">   &#125;);</span><br></pre></td></tr></table></figure>

<h3 id="其他资料"><a href="#其他资料" class="headerlink" title="其他资料"></a>其他资料</h3><p>​    Vuejs官网: <a href="https://cn.vuejs.org/" target="_blank" rel="noopener">https://cn.vuejs.org/</a></p>

      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2019/11/16/React/" rel="prev" title="React">
                React <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image"
                src="/images/1.jpg"
                alt="White" />
            
              <p class="site-author-name" itemprop="name">White</p>
              <p class="site-description motion-element" itemprop="description">君须知，未见之处，犹多宝藏</p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/archives/%7C%7Carchive">
              
                  <span class="site-state-item-count">10</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="/categories/index.html">
                  <span class="site-state-item-count">7</span>
                  <span class="site-state-item-name">分类</span>
                </a>
              </div>
            

            

          </nav>

          

          
            <div class="links-of-author motion-element">
                
                  <span class="links-of-author-item">
                    <a href="https://github.com/yourname" target="_blank" title="GitHub">
                      
                        <i class="fa fa-fw fa-github"></i>GitHub</a>
                  </span>
                
            </div>
          

          
          

          
          

          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-4"><a class="nav-link" href="#阶段要学习的内容"><span class="nav-number">1.</span> <span class="nav-text">阶段要学习的内容</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#简介-What"><span class="nav-number">2.</span> <span class="nav-text">简介(What)</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#为什么学-Why"><span class="nav-number">3.</span> <span class="nav-text">为什么学?(Why)</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#怎么学-How"><span class="nav-number">4.</span> <span class="nav-text">怎么学?(How)</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#VueJS注意事项"><span class="nav-number">5.</span> <span class="nav-text">VueJS注意事项</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#安装devTool工具"><span class="nav-number">6.</span> <span class="nav-text">安装devTool工具</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#使用VueJS"><span class="nav-number"></span> <span class="nav-text">使用VueJS</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#声明式渲染"><span class="nav-number">1.</span> <span class="nav-text">声明式渲染</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#指令"><span class="nav-number">2.</span> <span class="nav-text">指令</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#v-bind"><span class="nav-number">2.1.</span> <span class="nav-text">v-bind</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#v-on"><span class="nav-number">2.2.</span> <span class="nav-text">v-on</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#v-if"><span class="nav-number">2.3.</span> <span class="nav-text">v-if</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#v-else"><span class="nav-number">2.4.</span> <span class="nav-text">v-else</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#v-show"><span class="nav-number">2.5.</span> <span class="nav-text">v-show</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#v-for"><span class="nav-number">2.6.</span> <span class="nav-text">v-for</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#v-model"><span class="nav-number">2.7.</span> <span class="nav-text">v-model</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#v-once"><span class="nav-number">2.8.</span> <span class="nav-text">v-once</span></a></li></ol></li><li class="nav-item nav-level-4"><a class="nav-link" href="#事件详解"><span class="nav-number">3.</span> <span class="nav-text">事件详解</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#双向数据绑定原理"><span class="nav-number"></span> <span class="nav-text">双向数据绑定原理</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#其他资料"><span class="nav-number"></span> <span class="nav-text">其他资料</span></a></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2019</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">White</span>

  
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-heart"></i>
    </span>
    
      <span class="post-meta-item-text">Site words total count&#58;</span>
    
    <span title="Site words total count">26.9k</span>
  
</div>



<div class="theme-info">
  <div class="powered-by"></div>
  <span class="post-count">博客全站共26.9k 字</span>
</div>

        







        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
          <span id="scrollpercent"><span>0</span>%</span>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  
    <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.4"></script>



  
  

  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  












  





  

  

  

  
  

  

  

  

  

<script src="/live2dw/lib/L2Dwidget.min.js?094cbace49a39548bed64abff5988b05"></script><script>L2Dwidget.init({"model":{"jsonPath":"/live2dw/assets/hijiki.model.json"},"display":{"position":"right","hOffset":100,"width":150,"height":300},"mobile":{"show":true},"log":false,"pluginJsPath":"lib/","pluginModelPath":"assets/","pluginRootPath":"live2dw/","tagMode":false});</script></body>
</html>
